/** @odoo-module **/
const {
    markup,
    Component,
    onWillStart,
    useEnv,
    useSubEnv,
    useChildSubEnv,
    useRef,
    useState,
    mount,
    xml,
    whenReady,
    onMounted,
    onError,
    loadFile,
    onWillUpdateProps,
    useEffect,
    reactive,
    App,
    useComponent
} = owl;

import {Root} from './app.js'
let year_month = `2023-07`;

let menu_obj_list = [
    {
        title:'食材',
        icon:'icon-material',
        style:'top:235px;left:32px',
        list:[
            {title:'创建食材',url:'11',video:'//player.bilibili.com/player.html?isOutside=true&aid=1152514575&bvid=BV1mZ421q73h&cid=1489652530&p=1'},
            {title:'创建食材2',url:'22'}
        ]
    },
    {
        title:'菜品',
        icon:'icon-dish',
        style:'top:330px;left:32px',
        list:[
            {title:'创建食材',url:'11'},
            {title:'创建食材2',url:'22'},
            {title:'创建食材2',url:'22'},
        ]
    },
    {
        title:'客户配置',
        icon:'icon-cus',
        style:'top:139px;left:195px',
        list:[]
    },
    {
        title:'模板',
        icon:'icon-model',
        style:'top:330px;left:195px',
        list:[]
    },
    {
        title:'客户确认',
        icon:'icon-cus-comfirm',
        style:'top:139px;left:358px',
        list:[]
    },
    {
        title:'客户菜单',
        icon:'icon-cus-plan',
        style:'top:235px;left:358px',
        list:[]
    },
    {
        title:'供应商比价单',
        icon:'',
        style:'top:379px;left:358px',
        list:[]
    },
    {
        title:'确认供应商及价格',
        icon:'',
        style:'top:476px;left:358px',
        list:[]
    },
    {
        title:'日菜单',
        icon:'icon-day-plan',
        style:'top:235px;left:521px',
        list:[]
    },
    {
        title:'点餐',
        icon:'icon-order-dish',
        style:'top:332px;left:521px',
        list:[]
    },
    {
        title:'采购单',
        icon:'icon-purchase',
        style:'top:43px;left:718px',
        list:[]
    },
    {
        title:'领料单',
        icon:'icon-pick',
        style:'top:137px;left:718px',
        list:[]
    },
    {
        title:'切配单',
        icon:'icon-cut',
        style:'top:234px;left:718px',
        list:[]
    },
    {
        title:'分餐单',
        icon:'icon-distribution',
        style:'top:329px;left:718px',
        list:[
            {title:'创建食材',url:'11'},
            {title:'创建食材2',url:'22'},
            {title:'创建食材2',url:'22'},
        ]
    },
    {
        title:'排班',
        icon:'icon-work',
        style:'top:426px;left:718px',
        list:[]
    },
    {
        title:'入库',
        icon:'icon-stock-in',
        style:'top:43px;left:880px',
        list:[
            {title:'创建食材',url:'11'},
            {title:'创建食材2',url:'22'},
            {title:'创建食材2',url:'22'},
        ]
    },
    {
        title:'出库',
        icon:'icon-stock-out',
        style:'top:137px;left:880px',
        list:[]
    },
    {
        title:'客户成本比例',
        icon:'',
        style:'top:329px;left:880px',
        list:[]
    },
    {
        title:'库存',
        icon:'icon-stock',
        style:'top:91px;left:1046px',
        list:[]
    },
    {
        title:'非出库成本',
        icon:'',
        style:'top:233px;left:1046px',
        list:[]
    },
    {
        title:'销售录入',
        icon:'icon-sale-edit',
        style:'top:331px;left:1046px',
        list:[]
    },
    {
        title:'盘点',
        icon:'icon-inventory',
        style:'top:91px;left:1214px',
        list:[]
    },
    {
        title:'成本',
        icon:'icon-cost',
        style:'top:233px;left:1214px',
        list:[]
    },
    {
        title:'应收应付',
        icon:'icon-ysyf',
        style:'top:331px;left:1214px',
        list:[]
    },
    {
        title:'收入',
        icon:'icon-income',
        style:'top:426px;left:1214px',
        list:[]
    },
    {
        title:'现金流',
        icon:'icon-cash',
        style:'top:331px;left:1375px',
        list:[]
    },
    {
        title:'毛利',
        icon:'icon-profit',
        style:'top:331px;left:1565px',
        list:[]
    },
    {
        title:'利润表',
        icon:'icon-profit',
        style:'top:426px;left:1565px',
        list:[]
    },
];

let reactive_state = reactive({
    year_month,
    menu_obj_list,
    menu_url_dict: {},
})

class Parent extends Component {
    setup() {

        onError(err => {
            console.log(err.cause.message);
            alert(err.cause.message);
        })

        this.state = useState(reactive_state);

    }
}

Parent.template = xml`
    <Root menu_obj_list="state.menu_obj_list" menu_url_dict="state.menu_url_dict" />
`
Parent.components = {
    Root,
}

whenReady(async () => {
    // let templates = await loadFile('../xml/app.xml');
    let templates = await loadFile('./xml/app.xml');

    let app = new App(Parent, {
        env: {
            update_year_month(y_m) {
                reactive_state.year_month = y_m;
            }
        },
        dev: true,
    });

    app.addTemplates(templates);

    app.mount(document.body);
});

